package com.anhtuan.reminder.dialogs;

import java.util.Calendar;

import com.anhtuan.reminder.R;
import com.anhtuan.reminder.SelectionActivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.RadioButton;

public class DayPickerDialog extends DialogFragment {
	public int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle(R.string.day_picker_title)
				.setSingleChoiceItems(R.array.dayofweek, day - 1,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								day = which + 1;
							}
						})
				.setPositiveButton(R.string.picker_button_ok_text,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								SelectionActivity.day = day;
								RadioButton rb = (RadioButton) getActivity()
										.findViewById(R.id.rb_repeat_weekly);
								
								rb.setText(getResources().getString(R.string.repeat_weekly_text) + " "  + 
											String.format(getResources().getString(R.string.repeat_weekly_text_format),
													getResources().getStringArray(R.array.dayofweek)[day - 1]));
								dismiss();
							}
						})
				.setNegativeButton(R.string.picker_button_cacel_text, null);
		
		return builder.create();
	}
}
